<?php
/**
* @package      auto_occasion
* @subpackage   annonce
* @author       CMS
* @copyright    2011
* @license      All rights reserved
*/


/**
 * Classe permettant de gérer les annonces
 * ajout , rechercher, lister par type
 *
 */
class BoAnnonceTempCtrl extends jController {

    public $pluginParams = array(
        '*'=>array('auth.required'=>true)
        );

    /**
     * Recherche / liste annonce
     *
     *
     */
	function index() {
        $rep = $this->getResponse('html');
        
        $rep->addCSSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/css/jquery-ui.css');
        $rep->addCSSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/css/annonce.css');
		
		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/annonce.js');
		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jquery.ui.core.js');

        $rep->menusActifs = adminHtmlResponse::MENU_ANNONCES ;

        $photo= $this->param('photo', '');
		
        $rep->bodyTpl = 'annonce~BoAnnonceAdd';
        
        //$rep->body->assignZone ('oZoneAnnonceCaracteristique', 'annonce~BoAnnonceCaracteristique', array('search'=>$search)) ;
        //$rep->body->assignZone ('oZoneAnnonceEquipements','annonce~BoAnnonceEquipements', array('search'=>$search, 'iCurrentPage'=>$this->param('iCurrentPage', 1))) ;
        //$rep->body->assignZone ('oZoneAnnoncePartenaire', 'annonce~BoAnnoncePartenaire', array('search'=>$search)) ;
		//$rep->body->assignZone ('oZoneAnnonceCoordonnees','annonce~BoAnnonceCoordonnees', array('search'=>$search)) ;
        return $rep;
    }

    /**
     * Recherche / liste annonce par type
     *
     *
     */
	function listeParType() {
        $rep = $this->getResponse('html');
        
        jClasses::inc("annonce~annonceSrv");
        jClasses::inc ("commun~CNavBar") ;
        
        $rep->addCSSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/css/annonce.css');
		
		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/annonce.js');
		

        $rep->bodyTpl = 'annonce~BoAnnonceParType';
        $rep->menusActifs = adminHtmlResponse::MENU_ANNONCES ;


        $nbAnnonceAValider      = annonceSrv::countAnnonceAValider();
        $nbAnnonceAControler    = annonceSrv::countAnnonceAControler();
        $nbAnnonceEnLigne       = annonceSrv::countAnnonce(ANNONCE_ETAT_EN_LIGNE);
        $nbAnnonceArchivee      = annonceSrv::countAnnonce(ANNONCE_ETAT_ARCHIVEES);
        $nbAnnonceSupprimee     = annonceSrv::countAnnonce(ANNONCE_ETAT_SUPPRIMEES);
        $nbAnnoncePayeNonValide = annonceSrv::countAnnonceByPriceAndStates(ANNONCE_ETAT_PAYEE, ANNONCE_ETAT_NON_VALIDE);
        $nbAnnonceNonPayeValide = annonceSrv::countAnnonceByPriceAndStates(ANNONCE_ETAT_NON_PAYEE, ANNONCE_ETAT_VALIDE);
        $nbAnnonceNonValide     = annonceSrv::countAnnonceByPriceAndStates(false, ANNONCE_ETAT_NON_VALIDE, false);

        

        $iCurrentPage = $this->param("iCurrentPage",1);

		if ($iCurrentPage> 1){
			$iDebutListe = ($iCurrentPage-1) * ANNONCE_NBITEMPARPAGE; 
		}else{
			$iDebutListe = 0 ;
		}
		$oNavBar = new CNavBar (ANNONCE_NBITEMPARPAGE, 3) ;
		$oNavBar->iCurrPage = $iCurrentPage;
        
        $search        = new stdClass ();
        $search->type  = $this->param('type', '');

        $annonce = annonceSrv::recherche($search, $iDebutListe, ANNONCE_NBITEMPARPAGE);

        $oNavBar->normalizeBar ($annonce['nbRecords']) ;
		$oNavBar->mergeBar ();

		$rep->body->assign("oNavBar", $oNavBar) ;
        $rep->body->assign("nbAnnonceAValider", $nbAnnonceAValider) ;
        $rep->body->assign("nbAnnonceAControler", $nbAnnonceAControler) ;
        $rep->body->assign("nbAnnonceEnLigne", $nbAnnonceEnLigne) ;
        $rep->body->assign("nbAnnonceArchivee", $nbAnnonceArchivee) ;
        $rep->body->assign("nbAnnonceSupprimee", $nbAnnonceSupprimee) ;
        $rep->body->assign("nbAnnoncePayeNonValide", $nbAnnoncePayeNonValide) ;
        $rep->body->assign("nbAnnonceNonPayeValide", $nbAnnonceNonPayeValide) ;
        $rep->body->assign("nbAnnonceNonValide", $nbAnnonceNonValide) ;
	
        $rep->body->assign('annonce'       , $annonce['annonce']);
        $rep->body->assign('type'       , $search->type);
        
        return $rep;
    }



    /**
     * Editer une annonce
     *
     *
     */
	function editer() {
        $rep = $this->getResponse('html');
        
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/annonce.js');
        $rep->menusActifs = adminHtmlResponse::MENU_ANNONCES ;

        jClasses::inc("annonce~annonceEnrichissementSrv");
        jClasses::inc("annonce~annonceGarantieSrv");
        jClasses::inc("annonce~annonceOrigineSrv");
        jClasses::inc("annonce~annoncePaiementSrv");
        jClasses::inc("annonce~annonceParutionSrv");
        jClasses::inc("annonce~annoncePhotoSrv");
        jClasses::inc("annonce~annonceProvenanceSrv");
        jClasses::inc("annonce~annonceSourceSrv");
        jClasses::inc("annonce~annonceSrv");
        
        $enrichissement = annonceEnrichissementSrv::liste();
        $garantie       = annonceGarantieSrv::liste();
        $origine        = annonceOrigineSrv::liste();
        $paiement       = annoncePaiementSrv::liste();
        $parution       = annonceParutionSrv::liste();
        $photo          = annoncePhotoSrv::liste();
        $provenance     = annonceProvenanceSrv::liste();
        $source         = annonceSourceSrv::liste();
        $annonce        = annonceSrv::liste();


        $rep->body->assign('enrichissement', $enrichissement);
        $rep->body->assign('garantie'      , $garantie);
        $rep->body->assign('origine'       , $origine);
        $rep->body->assign('paiement'      , $paiement);
        $rep->body->assign('parution'      , $parution);
        $rep->body->assign('photo'         , $photo);
        $rep->body->assign('provenance'    , $provenance) ;
        $rep->body->assign('source'        , $source);
        $rep->body->assign('annonce'       , $annonce);

        $rep->bodyTpl = 'annonce~BoAnnonceEdit';

        return $rep;
    }
    /**
     * Editer une annonce
     *
     *@todo : Erick : mise en place du formulaire , phase 2 ajout annonce
     */
	function ajouter() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_ANNONCES ;

        $rep->bodyTpl = 'annonce~BoAnnonceAdd';

        return $rep;
    }

   /**
     * sauvegarder une annonce
     *
     *
     */
	 function sauvegarder() {
        $rep = $this->getResponse('redirect');
        
        jClasses::inc("annonce~annonceSrv");
		
		$annonce                             = new stdClass();
        $annonce->annonce_source_id          = $this->param('source','');
        $annonce->annonce_provenance_id      = $this->param('provenance','');
        $annonce->annonce_parution_id        = $this->param('parution','');
        $annonce->annonce_photo_id           = $this->param('photo','');
        $annonce->annonce_enrichissement_id  = $this->param('enrichissement','');
        $annonce->annonce_paiement_id        = $this->param('paiement','');
        $annonce->annonce_origine_id         = $this->param('origine','');
        $annonce->annonce_garantie_id        = $this->param('garantie','');
        $annonce->annonce_email              = $this->param('email','');
      
        annonceSrv::ajouter($annonce);
        
        $rep->action = 'annonce~BoAnnonce:index';


        return $rep;
    }

    
    /**
    * Supprime une annonce
    */
    function supprimer() {
        $rep = $this->getResponse('redirect');
        jClasses::inc('annonce~annonceSrv');

        $tabId = $this->param('tabId', '');

        annonceSrv::updateStatus($tabId);

        $rep->action = 'annonce~BoAnnonce:index';

        return $rep;
    }




   }

